<?php
namespace App\Http\Controllers\H5;

use App\Service\H5\ItemService;
use Illuminate\Http\Request;

class ItemController extends BaseController
{
    //列表
    public function index(Request $request)
    {
        $pas['depart_id'] = $request->post('depart_id', 0);
        $res = ItemService::index($pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    // 详情
    public function getOne(Request $request)
    {
        $id = $request->post('id', 0);
        $res = ItemService::getOne($id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['role_id'] = $request->post('role_id', 0);
        $pas['depart_id'] = $request->post('depart_id', 0);
        $pas['title'] = $request->post('title', '');
        $pas['leader_id'] = $request->post('leader_id', 0);
        $pas['starttime'] = $request->post('startday', '');
        $pas['endtime'] = $request->post('endday', '');
        if ($id) {
            $res = ItemService::modify($id, $pas);
        } else {
            $res = ItemService::add($pas);
        }
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //删除
    public function del(Request $request)
    {
        $id = $request->post('id', 0);
        $res = ItemService::del($id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }
}